const app = getApp();

Page({
  input:app.input,
  upload_img: app.upload_img,

  /**
   * 页面的初始数据
   */
  data: {
    SystemInfo: app.SystemInfo,
    
    list: [],
    list_name: [],

    repairType: "",
    repairType_name: "请选择报修类型",
    
    mrRoom: {
      nameCommunity: "当前无绑定房屋，请点击绑定房屋"
    },

    content: "",
    phone: "",

    img0: "",
    img1: "",
    img2: "",

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    app.init(this)

    app.api.client_repair_getRepairCategory({
      token: wx.getStorageSync("token"),
      idCommunity: wx.getStorageSync("idCommunity"),
    }, (res) => {
      let list_name = [];
      for (let i in res.data) {
        list_name.push(res.data[i].name)
      }
      this.setData({
        list: res.data,
        list_name: list_name
      })

    })


    app.api.client_community_getMrRoom({
      token: wx.getStorageSync("token"),
      idCommunity: wx.getStorageSync("idCommunity"),
    }, (res) => {
      if (res.data != undefined) {
        this.setData({
          mrRoom: res.data
        })
        wx.setStorageSync("mrRoom", res.data);
      }
    })

  },

  bindPickerChange: function (e) {
    console.log(e)
    this.setData({
      repairType: this.data.list[e.detail.value].id,
      repairType_name: this.data.list[e.detail.value].name
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },

  /*
  提交报修
  */
  client_complaintSuggest_add: function () {
    if (this.data.repairType == "") {
      app.toast("请选择报修类型");
      return false;
    }

    if (this.data.content == "") {
      app.toast("请填写报修内容");
      return false;
    }

    if (this.data.phone == "") {
      app.toast("请填写手机号码");
      return false;
    }

    let img = this.data.img0;
    if (this.data.img1 != "") {
      img = img + "," + this.data.img1
    }

    if (this.data.img2 != "") {
      img = img + "," + this.data.img2
    }

    app.api.client_complaintSuggest_add({
      token: wx.getStorageSync("token"),
      phone: this.data.phone,
      idRoom: this.data.mrRoom.idRoom,
      content: this.data.content,
      repairType: this.data.repairType,
      images: img,
    }, (res) => {
      if (res.status == 1) {
        wx.showModal({
          title: '提示',
          content: '报修成功',
          showCancel: false,
          success(res) {
            wx.redirectTo({
              url: '../feedback_list/feedback_list'
            })
          }
        })
      } else {
        app.toast(res.msg);
      }

    })





  },

  goto_house_bind: function () {
    if (this.data.mrRoom.nameCommunity == "当前无绑定房屋，请点击绑定房屋") {
      wx.navigateTo({
        url: '../house_bind/house_bind'
      })
    }
  },
  
})